using System;
using Slaks.Graphs.GraphBuilder;
namespace Slaks.Graphs.Algorithms.ExperimentalDistances
{
	public class MCSAdaptedVertexEdgeCount : GraphDistanceBase
	{
        public MCSAdaptedVertexEdgeCount()
            : base()
        {
        }

        public MCSAdaptedVertexEdgeCount(Graph one, Graph two) 
            : base ( one, two )
        {
        }
		public override bool CanOperateOnRepresentation (GraphBuilder.BuilderType builderType)
		{
			switch(builderType)
			{
			case      BuilderType.StandardRepresentationSchenker:
			case BuilderType.ExtractorBuilderNodesOnly:
			case BuilderType.StandardRepresentationSlaks:
			
				return true;
			}
			return false;
		}
		/// <summary>
		/// MCSadapted
		/// </summary>
		/// <param name="one"></param>
		/// <param name="two"></param>
		/// <returns></returns>
		public override double GetDistance()
		{
			Graph maxCommonSubgraph = (one.GetMCS(two));
			double commonSize = maxCommonSubgraph.GetGraphSizeVertexEdgeCount;
			double oneSize = one.GetGraphSizeVertexEdgeCount;
			double twoSize = two.GetGraphSizeVertexEdgeCount;

			if (Math.Abs(commonSize - oneSize) < Math.Abs(commonSize - twoSize))
			{
				if (commonSize < oneSize) return 1 - commonSize/oneSize;
				return 1 - commonSize/twoSize;
			}
			else
			{
				if (commonSize < twoSize) return 1 - commonSize/twoSize;
				return 1 - commonSize/oneSize;
			}
		}
	}
}